package com.rs.controller;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import com.rs.model.ZhOnBusiness;
import com.rs.service.ZhOnBusinessService;
import com.rs.util.DateFormatUtil;
import com.rs.util.SpringContextUtils;

import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import java.awt.Toolkit;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.ActionEvent;

public class ZhOnbusinessUpdate extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private JTextField txtS;
	private JTextField textField_2;
	private JTextField txtS_1;
	private JTextField txtSw;
	private JTextField txtS_2;
	private JTextField txtS_3;
	private JTextField txtS_4;
	private JTextField txtS_5;
	private JTextField textField_9;
	
	private ZhOnBusinessService zhOnBusinessService = SpringContextUtils.getBean(ZhOnBusinessService.class);

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ZhOnbusinessUpdate frame = new ZhOnbusinessUpdate(null,null);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public ZhOnbusinessUpdate(final ZhOnBusiness zhOnBusiness , final JDesktopPane desktopPane_1) {
		addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				ZhOnbusinessList zhLeanprogressList = new ZhOnbusinessList(desktopPane_1,zhOnBusiness.getOnAuid());
				zhLeanprogressList.setVisible(true);
				desktopPane_1.add(zhLeanprogressList);
			}
		});
		setIconImage(Toolkit.getDefaultToolkit().getImage(ZhOnbusinessUpdate.class.getResource("/images/logo1.png")));
		setTitle("修改");
		setBounds(100, 100, 620, 524);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("编号：");
		lblNewLabel.setBounds(56, 42, 54, 15);
		contentPane.add(lblNewLabel);
		
		textField = new JTextField();
		textField.setText(String.valueOf(zhOnBusiness.getOnId()));
		textField.setEditable(false);
		textField.setBounds(132, 39, 90, 21);
		contentPane.add(textField);
		textField.setColumns(10);
		
		JLabel lblNewLabel_1 = new JLabel("姓名：");
		lblNewLabel_1.setBounds(56, 100, 54, 15);
		contentPane.add(lblNewLabel_1);
		
		txtS = new JTextField();
		txtS.setText(zhOnBusiness.getOnUname());
		txtS.setEditable(false);
		txtS.setBounds(132, 97, 90, 21);
		contentPane.add(txtS);
		txtS.setColumns(10);
		
		JLabel lblNewLabel_2 = new JLabel("交通工具：");
		lblNewLabel_2.setBounds(56, 165, 66, 15);
		contentPane.add(lblNewLabel_2);
		
		textField_2 = new JTextField();
		textField_2.setText(zhOnBusiness.getOnTraffic());
		textField_2.setEditable(false);
		textField_2.setBounds(132, 162, 90, 21);
		contentPane.add(textField_2);
		textField_2.setColumns(10);
		
		JLabel lblNewLabel_3 = new JLabel("目的城市：");
		lblNewLabel_3.setBounds(56, 220, 66, 15);
		contentPane.add(lblNewLabel_3);
		
		txtS_1 = new JTextField();
		txtS_1.setText(zhOnBusiness.getOnMdcity());
		txtS_1.setEditable(false);
		txtS_1.setBounds(132, 217, 90, 21);
		contentPane.add(txtS_1);
		txtS_1.setColumns(10);
		
		JLabel lblNewLabel_4 = new JLabel("开始时间：");
		lblNewLabel_4.setBounds(325, 42, 66, 15);
		contentPane.add(lblNewLabel_4);
		
		txtSw = new JTextField();
		txtSw.setText(DateFormatUtil.getDateStringw(zhOnBusiness.getOnKtime(),"yyyy-MM-dd"));
		txtSw.setEditable(false);
		txtSw.setBounds(413, 39, 90, 21);
		contentPane.add(txtSw);
		txtSw.setColumns(10);
		
		JLabel lblNewLabel_5 = new JLabel("结束时间：");
		lblNewLabel_5.setBounds(325, 100, 66, 15);
		contentPane.add(lblNewLabel_5);
		
		txtS_2 = new JTextField();
		txtS_2.setText(DateFormatUtil.getDateStringw(zhOnBusiness.getOnKtime(),"yyyy-MM-dd"));
		txtS_2.setEditable(false);
		txtS_2.setBounds(413, 97, 90, 21);
		contentPane.add(txtS_2);
		txtS_2.setColumns(10);
		
		JLabel lblNewLabel_6 = new JLabel("天数/天：");
		lblNewLabel_6.setBounds(325, 165, 54, 15);
		contentPane.add(lblNewLabel_6);
		
		txtS_3 = new JTextField();
		txtS_3.setText(String.valueOf(zhOnBusiness.getOnDays()));
		txtS_3.setEditable(false);
		txtS_3.setBounds(413, 162, 90, 21);
		contentPane.add(txtS_3);
		txtS_3.setColumns(10);
		
		JLabel lblNewLabel_7 = new JLabel("备注：");
		lblNewLabel_7.setBounds(325, 220, 54, 15);
		contentPane.add(lblNewLabel_7);
		
		JTextPane txtpnS = new JTextPane();
		txtpnS.setText(zhOnBusiness.getOnReason());
		txtpnS.setEditable(false);
		txtpnS.setBounds(413, 220, 162, 115);
		contentPane.add(txtpnS);
		
		JLabel lblNewLabel_8 = new JLabel("审批人：");
		lblNewLabel_8.setBounds(56, 288, 54, 15);
		contentPane.add(lblNewLabel_8);
		
		txtS_4 = new JTextField();
		txtS_4.setText(zhOnBusiness.getOnAuname());
		txtS_4.setEditable(false);
		txtS_4.setBounds(132, 285, 90, 21);
		contentPane.add(txtS_4);
		txtS_4.setColumns(10);
		
		JLabel lblNewLabel_9 = new JLabel("审核状态：");
		lblNewLabel_9.setBounds(56, 348, 66, 15);
		contentPane.add(lblNewLabel_9);
		
		txtS_5 = new JTextField();
		txtS_5.setText(String.valueOf(zhOnBusiness.getOnAudit()));
		txtS_5.setBounds(132, 345, 90, 21);
		contentPane.add(txtS_5);
		txtS_5.setColumns(10);
		
		textField_9 = new JTextField();
		textField_9.setEditable(false);
		textField_9.setText("审核状态（0.待审核 1.审核通过 2.审核未通过）");
		textField_9.setBounds(244, 345, 282, 21);
		contentPane.add(textField_9);
		textField_9.setColumns(10);
		
		JButton btnNewButton = new JButton("修改");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int a =zhOnBusiness.getOnAuid();
				ZhOnBusiness zhOnBusiness = new ZhOnBusiness();
				zhOnBusiness.setOnId(Integer.parseInt(textField.getText()));
				zhOnBusiness.setOnAudit(Integer.parseInt(txtS_5.getText()));
				zhOnBusiness.setOnAuid(a);
				zhOnBusinessService.updateOnBusinessAudit(zhOnBusiness);
				showMessageDialog("修改成功");
			}
		});
		btnNewButton.setBounds(433, 435, 93, 23);
		contentPane.add(btnNewButton);
	}
	//提示弹窗
			public void showMessageDialog(String massage){
				JOptionPane.showMessageDialog(this,massage);
			}
}
